
package ucm.module;

import air_cp5620.dao.DAO;
import javax.swing.JOptionPane;
import java.sql.*;


public class UC_ModM {

    private DAO dbCon = null;
    private String id = null;

    public UC_ModM(String id) {
        this.id = id;
        dbCon = new DAO();
    }


    public boolean modify(String start_city, String end_city,String start_time,String end_time,String ticketcount,String price) {
        String sql = null;
        Connection con = dbCon.getConnection();
        if (con == null) {
            JOptionPane.showMessageDialog(null, "Don't get connection!");
            return false;
        }
        try {
            Statement stmt = con.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.CONCUR_UPDATABLE);
            sql = "update tbl_air_info set start_city='" + start_city + "',end_city='" + end_city + "'," +
                    "start_time=date_format('" + start_time + "','%Y-%m-%d %H:%i:%s'),end_time=date_format('" + start_time + "','%Y-%m-%d %H:%i:%s')," +
                    "ticketcount='" + ticketcount + "',price='" + price + "' where id='" + id + "'";
            stmt.executeUpdate(sql);
            JOptionPane.showMessageDialog(null, "Modify air info is successful!");
            return true;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Modify air info error！");
            e.printStackTrace();
            return false;
        }
    }
}
